﻿using Domain.Process_Procedures;
using Infratructure.Interface;
using MediatR;
using MES.Server.API.Application.Command.Process_Procedures.ProcessFlow;
using ReturnValue;

namespace MES.Server.API.Application.Handler.Process_Procedures.ProcessFlow
{
    public class DelProcessFlowHandler : IRequestHandler<DelProcessFlowCommand, ApiResult<int>>
    {
        private readonly IRepository<ProcessFlowModel> _processFlowRepo;

        public DelProcessFlowHandler(IRepository<ProcessFlowModel> processFlowRepo)
        {
            _processFlowRepo = processFlowRepo;
        }

        public async Task<ApiResult<int>> Handle(DelProcessFlowCommand request, CancellationToken cancellationToken)
        {
            var d= await _processFlowRepo.GetValue(request.Id);
            if (d == null)
            {
                return new ApiResult<int>().Fail("流程不存在");
            }
            d.IsDel = true;
            var r=await _processFlowRepo.UpdateAsync(d);
            if (r > 0)
            {
                return new ApiResult<int>().Success("删除成功", r);
            }
            else
            {
                return new ApiResult<int>().Fail("删除失败");
            }
        }
    }
}
